﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeBehind="Manufacture_Loan.aspx.cs" Inherits="Project_Udrinkwater.PagesAdmin.Manufacture_Loan" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
     <dx:ASPxRoundPanel ID="RPN_SalaryEmp" runat="server" Width="100%" 
         HeaderText="รายการเบิกวัตถุดิบ">
        <HeaderStyle Font-Size="Medium" HorizontalAlign="Left" />
<PanelCollection>
<dx:PanelContent runat="server" SupportsDisabledAttribute="True"></dx:PanelContent>
</PanelCollection>
</dx:ASPxRoundPanel>
     <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                        Text="พิมพ์รายงาน" />
    <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="dsManufacture_Loan" KeyFieldName="ID" Width="100%">
        <Columns>
            <dx:GridViewCommandColumn VisibleIndex="6" ShowSelectCheckbox="True" 
                Caption="ทำรายการ">
                <NewButton Text="เพิ่ม" Visible="True">
                </NewButton>
                <DeleteButton Text="ลบ" Visible="True">
                </DeleteButton>
                <ClearFilterButton Visible="True">
                </ClearFilterButton>
            </dx:GridViewCommandColumn>
            <dx:GridViewDataComboBoxColumn Caption="ชื่อวัตถุดิบ" FieldName="Product_ID" 
                VisibleIndex="2">
                <PropertiesComboBox DataSourceID="dsProduct_ID" TextField="Product_Name" 
                    ValueField="Product_ID">
                </PropertiesComboBox>
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataTextColumn FieldName="ID" ReadOnly="True" Visible="False" 
                VisibleIndex="0">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataComboBoxColumn Caption="พนักงานที่เบิก" FieldName="Employee_ID" 
                VisibleIndex="3">
                <PropertiesComboBox DataSourceID="dsEmployee_ID" TextField="FullName" 
                    ValueField="Employee_ID">
                </PropertiesComboBox>
            </dx:GridViewDataComboBoxColumn>
            <dx:GridViewDataDateColumn Caption="วันที่" FieldName="Date_Take" 
                VisibleIndex="4">
            </dx:GridViewDataDateColumn>
            <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Amout" VisibleIndex="5">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn Caption="ลำดับ" FieldName="RowID" VisibleIndex="1">
                <EditFormSettings Visible="False" />
            </dx:GridViewDataTextColumn>
        </Columns>
        <SettingsBehavior ConfirmDelete="True" />
        <Settings ShowFilterRow="True" />
        <SettingsText ConfirmDelete="ยืนยันการลบ" />
    </dx:ASPxGridView>
    <asp:SqlDataSource ID="dsManufacture_Loan" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        DeleteCommand="DELETE FROM [TB_Manufacture_Loan] WHERE [ID] = @ID" InsertCommand="INSERT INTO TB_Manufacture_Loan(Employee_ID, Product_ID, Date_Take, Amout) VALUES (@Employee_ID, @Product_ID, @Date_Take, @Amout);
Update TB_Product 
SET TB_Product.In_Stock =  TB_Product.In_Stock - @Amout
WHERE TB_Product.Product_ID = @Product_ID
" 
        SelectCommand="SELECT [Product_ID], [ID],ROW_NUMBER() OVER (ORDER BY TB_Manufacture_Loan.ID) AS RowID, [Employee_ID], [Date_Take], [Amout] FROM [TB_Manufacture_Loan]" 
        UpdateCommand="UPDATE [TB_Manufacture_Loan] SET [Product_ID] = @Product_ID, [Employee_ID] = @Employee_ID, [Date_Take] = @Date_Take, [Amout] = @Amout WHERE [ID] = @ID">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Employee_ID" Type="String" />
            <asp:Parameter Name="Product_ID" Type="String" />
            <asp:Parameter DbType="Date" Name="Date_Take" />
            <asp:Parameter Name="Amout" Type="Int32" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Product_ID" Type="String" />
            <asp:Parameter Name="Employee_ID" Type="String" />
            <asp:Parameter DbType="Date" Name="Date_Take" />
            <asp:Parameter Name="Amout" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsEmployee_ID" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        SelectCommand="SELECT Employee_ID, FirstName + ' ' + LastName AS FullName FROM TB_Employee">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsProduct_ID" runat="server" 
        ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>" 
        
        SelectCommand="SELECT Product_ID, Product_Name FROM TB_Product WHERE (Product_Category_ID = 02)">
    </asp:SqlDataSource>
    <dx:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" 
        ExportedRowType="Selected">
        <Styles>
            <Default Font-Names="Angsana New">
            </Default>
        </Styles>
        <PageHeader Right="[Pages #]
[Date Printed]">
        </PageHeader>
    </dx:ASPxGridViewExporter>
</asp:Content>
